package lc;
import org.junit.*;
import util.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Ex328 {
    class Solution {
        public ListNode oddEvenList(ListNode head) {
            ListNode pRes = new ListNode(0), qRes =new ListNode(0), pResult = pRes, qResult = qRes, cur = head, tmp;
            while (cur != null && cur.next != null) {
                tmp = cur.next.next;
                pRes.next = cur;
                pRes = pRes.next;
                qRes.next = cur.next;
                qRes = qRes.next;
                cur = tmp;
            }
            if (cur != null) {
                qRes.next = null;
                pRes.next = cur;
                pRes = pRes.next;
            }
            pRes.next = qResult.next;
            return pResult.next;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        ListNode head = ListNode.newListNodeFromArray(new int[]{1,2,3});
        System.out.println(s.oddEvenList(head));  

        // String[] ss = {"abc", "ABC"};
        // Stream<Stream<String>> strs = Arrays.stream(ss).map(Ex328::getStream);
        // Stream<String> strs2 = Arrays.stream(ss).flatMap(Ex328::getStream);
    }
    
    public static Stream<String> getStream(String s) {
        List<String> list = new ArrayList<>();
         for (char c: s.toCharArray()) {
            list.add(c + "");
        }
        return list.stream();
    }
}
